<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="navbar" v-if="hideNavigationBar">
			<u-navbar title="模型详情" height="120rpx" leftText="返回" @leftClick="gotoBack" :autoBack="true">
			</u-navbar>
		</view>
		<!-- 模型渲染 -->
		<view class="content" :class="{'content-top': hideNavigationBar}">
			<model-render :modelUrl="modelUrl"></model-render>
		</view>

	</view>
</template>


<script>
	import modelRender from '@/components/model-render/index.vue'

	export default {
		name: "",
		components: {
			modelRender
		},
		data() {
			return {
				modelUrl: "",
				envType: {},
				messageData: {},
				hideNavigationBar: true,
			};
		},
		create() {

		},
		onLoad: function(option) {
			//console.log(window.location.href)
			let that = this;
			uni.webView.getEnv(function(res) {
				console.log('当前环境：' + JSON.stringify(res));
				that.envType = res
				if(that.envType.miniprogram){
					that.hideNavigationBar = false;
				}
			});
			this.modelUrl = this.$route.query.modelUrl
		},
		methods: {
			gotoBack() {

				this.jumpPage('/pages/home/home');
				// this.sendMessage(this.messageData);
			},
			// 跳转页面
			jumpPage(url) {
				if (this.envType.h5 || this.envType.plus) {
					// 返回H5或者APP页面
					uni.webView.switchTab({
						url: '/pages/home/home'
					})
				} else if (this.envType.miniprogram) {
					//返回微信小程序页面
					jWeixin.miniProgram.switchTab({
						url: '/pages/home/home'
					})
				}
			},
			// 发送消息
			sendMessage(data) {
				if (this.envType.h5) {
					//给H5发送消息
					window.parent.postMessage({
						type: "message",
						data: data
					}, "*")
				} else if (this.envType.miniprogram) {
					//给微信小程序发送消息(只有页面销毁、分享、后退的时候才发送)
					// uni.webView.postMessage 也能发送
					jWeixin.miniProgram.postMessage({
						data,
					});
					// 通过触发后退发送消息但没成功
					jWeixin.miniProgram.navigateBack()
				} else if (this.envType.plus) {
					//给APP发送消息
					uni.webView.postMessage({
						data,
					});
				}
			}
		},
	}
</script>

<style scoped>
	.container {}
	.content {
		height: 100vh;
		box-sizing: border-box;
	}
	.content-top{
		padding-top: 120rpx;
	}
</style>